<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/1
 * Time: 11:23
 */

namespace app\admin\controller;


use app\common\controller\AdminBase;
use app\common\model\SkillDisplaym;
use think\Db;

class Skilldisplay extends AdminBase
{
    /**
     * 名片列表
     */
    public function index($status = '', $page = 1)
    {
        $map = [];
        if ($status && $status != 0){
            $map= ['sd_status' => $status];
        }
        $list = SkillDisplaym::skillDisplayList($map, $page);
        $allnum = Db::name('skill_display')->count();//总数量
        $unpublishednum = Db::name('skill_display')->where('sd_status', 1)->count();//未发布数量
        $auditednum = Db::name('skill_display')->where('sd_status', 2)->count();//待审核数量
        $adoptdnum = Db::name('skill_display')->where('sd_status', 3)->count();//审核成功数量
        return $this->fetch('index', ['list' => $list, 'status' => $status,  'allnum' => $allnum, 'unpublishednum' => $unpublishednum, 'auditednum' => $auditednum, 'adoptdnum' => $adoptdnum]);
    }
    /**
     * 审核名片
     */
    public function edit($id, $status, $res, $uid, $sdtitle)
    {
        $res1 = false;
        if ($status == 2) {
            $res1 = SkillDisplaym::editSkillDisplay($id, $res, $uid, $sdtitle);
        } elseif ($status == 4) {
            $res1 = SkillDisplaym::editSkillDisplay($id, $res, $uid, $sdtitle);
        } else {
            $this->error('更新失败');
        }
        if (!$res1) {
            $this->error('更新失败');
        }
        $this->success('更新成功');
    }

    /**
     * 名片的详情
     */
    public function detail($id)
    {
        return $this->fetch('detail', ['detail' => SkillDisplaym::skillDisplayDetail($id)]);
    }

}